package com.bootx.controller.api;

import com.bootx.common.Result;
import com.bootx.controller.BaseController;
import com.bootx.entity.BaseEntity;
import com.bootx.entity.Lottery;
import com.bootx.service.LotteryService;
import com.fasterxml.jackson.annotation.JsonView;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author black
 */
@RestController
@RequestMapping("/api/config")
public class ConfigController extends BaseController {

    @Resource
    private LotteryService lotteryService;

    @PostMapping("/edit")
    @JsonView(BaseEntity.EditView.class)
    public Result edit(){
        return Result.success(lotteryService.find(2L));
    }

    @PostMapping("/save")
    @JsonView(BaseEntity.EditView.class)
    public Result save(Lottery lottery){

        Lottery old = lotteryService.find(lottery.getId());
        old.setWalletIndex(lottery.getWalletIndex());
        old.setPredictionCount(lottery.getPredictionCount());
        lotteryService.update(old);
        return Result.success();
    }

}
